import React from 'react';
import { Checkbox, message } from 'antd';
export default (props) => {
    const { type, title, datas, fieldNames, currentValue, clickConfirm } = props;
    return <div className="offwards">
        <div className="restrict">{title}：</div>
        {datas.map((item, index) => (
            <div key={item[fieldNames.value]}>
                <Checkbox
                    checked={item.checked}
                    onChange={(e) => {
                        let keyword = e.target.checked;
                        let collectList = [];
                        datas.map((items) => {
                            if (items.checked) {
                                collectList.push(item[fieldNames.value]);
                            }
                        });
                        if (keyword && collectList.length > 2) {
                            message.info('选择科目不可超过三个');
                            return;
                        }
                        datas[index].checked = keyword
                        let totalList = []
                        datas.map((items) => {
                            if (items.checked) {
                                totalList.push(item[fieldNames.value]);
                            }
                        })
                        if (totalList.length) {
                            clickConfirm(totalList.join(','));
                        } else {
                            clickConfirm('');
                        }
                    }}
                >
                    {item[fieldNames.label]}
                </Checkbox>
            </div>
        ))}
    </div>

}
